﻿@model PagingInfo
@{
    int pageIndex = this.Model.PageIndex;
    int pageSize = this.Model.PageSize;
    int totalPages = this.Model.TotalPageCount;
    int totalItems = this.Model.TotalItemCount;
}
<div id="pagingDiv">
    <a href="javascript:void();" onclick="GotoPage(null, 1, $('#pageSize').val());">@Locale.GetString("Vit.Web", "DataPager_FirstPage")</a>
    <a href="javascript:void();" onclick="GotoPage(null, @(pageIndex - 1 > 1 ? pageIndex - 1 : 1), $('#pageSize').val());">@Locale.GetString("Vit.Web", "DataPager_PrevPage")</a>
    <a href="javascript:void();" onclick="GotoPage(null, @(pageIndex + 1 < totalPages ? pageIndex + 1 : totalPages), $('#pageSize').val());">@Locale.GetString("Vit.Web", "DataPager_NextPage")</a>
    <a href="javascript:void();" onclick="GotoPage(null, @(totalPages), $('#pageSize').val());">@Locale.GetString("Vit.Web", "DataPager_LastPage")</a>
    <span>@string.Format(Locale.GetString("Vit.Web", "DataPager_PageInfo"), pageIndex, totalPages, totalItems)</span>
    <span>@Locale.GetString("Vit.Web", "DataPager_PageSize")</span>
    <select id='pageSize' onchange='$.cookie("pageSize", $(this).val());'>
        <option value="10" @((pageSize == 10 ? "selected='selected'" : "").ToHtmlString())>10</option>
        <option value="20" @((pageSize == 20 ? "selected='selected'" : "").ToHtmlString()) >
            20</option>
        <option value="50" @((pageSize == 50 ? "selected='selected'" : "").ToHtmlString()) >
            50</option>
        <option value="100" @((pageSize == 100 ? "selected='selected'" : "").ToHtmlString()) >
            100</option>
        <option value="200" @((pageSize == 200 ? "selected='selected'" : "").ToHtmlString()) >
            200</option>
    </select>
    <span>@Locale.GetString("Vit.Web", "DataPager_GotoInfo")</span>
    <select id='gotoPage'>
        @for (int i = 1; i <= totalPages; i++)
        {
            <option value="@i" @((i == pageIndex ? "selected='selected'" : "").ToHtmlString())>@i</option>
        }
    </select>
    <a href="javascript:void();" onclick="GotoPage(null, $('#gotoPage').val(), $('#pageSize').val());">@Locale.GetString("Vit.Web", "DataPager_GotoPage")</a>
</div>
<script type="text/javascript">
    function GotoPage(url, pi, ps) {
        if (pi < 1)
            pi = 1;
        var form = $('#filter-form');
        if (form && form.is('form')) {
            if (!url)
                url = form.attr('action');
            form.append("<input type='hidden' id='pi' name='pi' value='" + pi.toString() + "'/>");
            form.append("<input type='hidden' id='ps' name='ps' value='" + ps.toString() + "'/>");
            form.attr('action', url);
            form.trigger('beforeSubmit');
            form.submit();
        }
        else {
            if (!url)
                url = window.location.pathname + $.query.load(window.location.href).set('pi', pi).set('ps', ps).toString();
            window.location.href = url;
        }
    }

    $(function () {
        var userPager = $.cookie('pageSize');
        if (userPager)
            $('#pageSize').val(userPager);
    });
</script>
